package com.itheima.controller;

import com.itheima.dto.ClazzQueryParam;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(clazzService.getById(id));
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        clazzService.deleteById(id);
        return Result.success();
    }

    @GetMapping
    public Result list(ClazzQueryParam clazzQueryParam){
        PageResult pageResult = clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }

    @GetMapping("/list")
    public Result findAll(){
        return Result.success(clazzService.findAll());
    }

    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        return Result.success(clazzService.add(clazz));
    }

}
